home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 669 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.9 KB  |  89 lines

  1. Path: chronicle.mti.sgi.com!austern
  2. From: aeb@saltfarm.bt.co.uk (Tony Bass)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: 'const' in header files
  5. Date: 08 Mar 1996 09:14:15 PST
  6. Organization: BT Speech Technology Section
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4hpd36$m42@calf.saltfarm.bt.co.uk>
  9. References: <4hn54s$3am@engnews1.Eng.Sun.COM>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 8 Mar 1996 13:35:34 -0000
  12. Posted-Date: Fri, 8 Mar 1996 13:35:35 GMT
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMUBq/Uy4NqrwXLNJAQEkGgH+MJmH5pR9tbj5tKKsw05harICTKHQoSf4
  15.     Mkfh+yOv69kCTbgVMMUhFsLgApfGn21ATKeJHJeeekVDM3XKN12mOQ==
  16.     =3bow
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. >From article <4hn54s$3am@engnews1.Eng.Sun.COM>, by clamage@Eng.Sun.COM (Steve Clamage):
  20.  
  21. [... other interesting discussion]
  22. > I suppose I should also comment on the comparison with unneeded template
  23. > instantiations. That isn't an optimization issue, but a correctness issue.
  24. > Simple example:
  25. >     template< class T > class X {
  26. >         T t;
  27. >         ...
  28. >         bool operator<( const T& rhs ) { return t < rhs.t; }
  29. >     };
  30. > Suppose we instantiate X on a type T for which the "<" operator is not
  31. > defined. That isn't a problem unless we invoke X<T>::operator<. So the
  32. > language rule is that a compiler can't reject a program due to an
  33. > invalid instantiation unless the instantiation is actually required.
  34. [...]
  35.  
  36.  
  37. Presumably this language rule also covers the situation below with an
  38. incomplete type, and my C++ compiler (HP-UX cfront-based) is incorrect
  39. to reject it?
  40.  
  41.  
  42. I had an example where I needed only pointers,
  43.  
  44.    template<struct T> struct VBlock;
  45.    struct VScratchRep;
  46.  
  47.    struct VScratch {
  48.      VScratchRep *chunk;
  49.      VBlock<VScratchRep> *free;
  50.     };
  51.  
  52.    int main()
  53.    {
  54.     VScratch *p = (VScratch *)0;
  55.     return 0;
  56.    }
  57.  
  58. which the compiler would accept in isolation, but if during the same
  59. compilation it saw the definition of VBlock<T>::operator[],
  60.  
  61.    template<struct T> struct VBlock {
  62.      T &operator[](int i);
  63.      T *v;
  64.     };
  65.  
  66.    template<struct T> inline T &VBlock<T>::operator[](int i)
  67.    {
  68.     return v[i];
  69.    }
  70.  
  71. it failed, needing to know the size of VScratchRep even though [] was
  72. never called in this compilation.  (I discovered this when including two
  73. header files while compiling something else.)
  74.  
  75.     Tony Bass
  76.  
  77. -- 
  78. # Tony Bass                                     Tel: (01473) 645305
  79. # MLB 3/19, BT Laboratories                     e-mail: aeb@saltfarm.bt.co.uk
  80. # Martlesham Heath, Ipswich, Suffolk, IP5 7RE   DO NOT e-mail to From: line
  81. #                                               Opinions are my own
  82. ---
  83. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  84.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  85.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  86.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  87.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  88. ]
  89.